package cn.web.tunnelrobot.controller;

import cn.web.tunnelrobot.dto.UserRecordDTO;
import cn.web.tunnelrobot.pojo.UserRecord;
import cn.web.tunnelrobot.service.UserRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 信息汇总
 * @version 1.0.0
 *
 */
@RestController
@RequestMapping("/UserRecordController")
public class UserRecordController {
    @Autowired
    private UserRecordService userRecordService;
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//注意月份是MM
    //private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @GetMapping("/getUserRecordList")
    @ResponseBody
    public HashMap<String, Object> getUserRecordList(@RequestParam(value ="usName", required = false) String usName,
                                                     @RequestParam(value ="urOperatContent", required = false) String urOperatContent,
                                                     @RequestParam(value ="urOperatTime", required = false) String urOperatTime,
                                                     @RequestParam(value = "pageNo", defaultValue = "1", required = false) Integer pageNo,
                                                     @RequestParam(value = "pageSize", defaultValue = "20", required = false) Integer pageSize) throws ParseException {
        UserRecordDTO userRecordDTO = new UserRecordDTO();
        userRecordDTO.setPageNo((pageNo-1)*pageSize);
        userRecordDTO.setPageSize(pageSize);
        userRecordDTO.setUrOperatContent(urOperatContent);
        userRecordDTO.setUsName(usName);
        //System.out.println("警告列表传入的时间:"+urOperatTime);
        Date urOperatTimes = null;
        if(urOperatTime != null && urOperatTime.trim()!=""){
            urOperatTimes = simpleDateFormat.parse(urOperatTime);
            userRecordDTO.setUrOperatTime(urOperatTimes);
        }
        return userRecordService.getUserRecordList(userRecordDTO);
    }

    @GetMapping("/getInfoStatistical")
    @ResponseBody
    public HashMap<String, Object> InfoStatistical(@RequestParam(value ="operStartTime", required = false) String operStartTime,
                                                   @RequestParam(value ="operEndTime", required = false) String operEndTime){
        return userRecordService.InfoStatistical(operStartTime,operEndTime);
    }
}
